﻿String.prototype.parseDate = function() {
    return new Date(parseInt(this.replace("/Date(", "").replace(")/", ""), 10));
};

String.prototype.replaceAll = function(searchvalue, newvalue) {
    var s = this;
    while (s.indexOf(searchvalue) >= 0)
        s = s.replace(searchvalue, newvalue);
    return s;
};
Date.prototype.addDays = function(n) {
    this.setDate(this.getDate() + n);
    return this;
};

Date.prototype.addHours = function(h) {
    this.setHours(this.getHours() + h);
    return this;
};
Date.prototype.addMinutes = function(m) {
    this.setMinutes(this.getMinutes() + m);
    return this;
};

String.format = String.prototype.format = function() {
    var i = 0;
    var string = (typeof(this) == "function") ? arguments[0] : this;

    for (; i < arguments.length; i++)
        string = string.replace(/\{\d+?\}/, arguments[i]);

    return string;
};

Date.prototype.format = function (format, concatFormat) {
    concatFormat = concatFormat || '';
    format = format || TMM.Global.getCalendarPatterns().d;
    format += concatFormat;

    return TMM.Global.format(this, format).trim();
};

Date.prototype.formatDateTime = function () {
    return this.format(null, " HH:mm:ss tt");
};